﻿using System;
using System.Collections.Generic;
using System.ComponentModel;

namespace System.ApplicationModel
{
    public partial class Entity : IRevertibleChangeTracking
    {
        #region IRevertibleChangeTracking Implementation
        /// <summary>
        /// Resets the object’s state to unchanged by rejecting the modifications.
        /// </summary>
        public void RejectChanges()
        {
            if (object.ReferenceEquals(this._backup, null))
                return;

            foreach (KeyValuePair<string, dynamic> item in this._backup)
            {
#if SILVERLIGHT
                this.GetType().GetProperty(item.Key).SetValue(this, (object)item.Value, null);
#else
                TypeDescriptor.GetProperties(this)[item.Key].SetValue(this, item.Value);
#endif
            }

            this._backup = null;
            this.IsChanged = false;
        }
        #endregion
	}
}
